package nix.mall.item.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import nix.mall.item.pojo.ItemExt;
import nix.mall.pojo.Item;
import nix.mall.pojo.ItemDesc;
import nix.mall.service.ItemService;

/**
 * 商品详情页Controller
 */
@Controller
public class ItemController {

	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/item/{itemId}")
	public String showItem(@PathVariable Long itemId, Model model) {
		// 商品基本信息
		Item item = itemService.getItemById(itemId);
		ItemExt itemExt = new ItemExt(item);
		// 商品详情
		ItemDesc itemDesc = itemService.getItemDescById(itemId);
		// 传递至页面
		model.addAttribute("item", itemExt);
		model.addAttribute("itemDesc", itemDesc);
		// 返回逻辑视图
		return "item";
	}
}